<template>
    <view>
        <view class="topbar" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
            <text @tap="topbarFn" :class="'item ' + (currentTab == index ? 'active' : '')" :data-idx="index" v-for="(item, index) in topbar" :key="index">{{ item }}</text>
        </view>
        <view class="my_loveb_ye" v-if="currentTab == 0">
            <view class="box">
                <view class="dt">
                    <text class="i ico" :style="'--color:' + color"></text>
                </view>
                <view class="dd">
                    <text class="loveb_str">当前{{ loveb_str }}</text>
                    <view class="span LoveB" :style="'--color:' + color + ';'">
                        {{ loveb }}
                        <text class="font">个</text>
                    </view>
                </view>
            </view>
        </view>
        <block v-if="currentTab == 1">
            <view class="my_loveb_mx" v-if="LIST.length > 0">
                <block v-for="(dl, idx_list) in LIST" :key="idx_list">
                    <view class="dl" :data-uid="item.id" v-for="(item, idx_dl) in dl" :key="idx_dl">
                        <view class="dt">
                            {{ item.c }}
                            <text class="font">{{ item.addtime }}</text>
                        </view>

                        <view :class="'dd ' + item.class">{{ item.num }}</view>
                    </view>
                </block>
            </view>
            <view class="nodata" v-if="nodatabox">
                <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                暂无信息
            </view>
        </block>
        <block v-if="currentTab == 2">
            <view class="my_loveb_cz" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor" v-if="CZ.list.length > 0">
                <form>
                    <view class="dl">
                        <view class="dt">充值数量</view>
                        <view class="dd">
                            <view
                                @tap="czliFn"
                                :class="'em ' + (CZ.defkey == item_index ? 'ed' : '')"
                                :data-idx="item_index"
                                v-for="(item, item_index) in CZ.list"
                                :key="item_index"
                            >
                                {{ item.num }}{{ CZ.dw }}
                            </view>
                        </view>
                    </view>
                    <view class="dl rmbdl">
                        <view class="dt">实付金额</view>
                        <view class="dd">
                            <text class="span">{{ CZ.list[CZ.defkey].rmb }}元</text>
                            <text class="span" v-if="CZ.zk < 1">
                                （{{ CZ.zk_str }}
                                <text class="s">原价{{ CZ.list[CZ.defkey].rmb_yj }}元</text>
                                ）
                            </text>
                        </view>
                    </view>
                    <view class="btnbox">
                        <button @tap="payFn" class="btn44" type="button">在线支付购买</button>
<!--                        <navigator class="btn44" url="/myPages/hongniang/hongniang">联系经纪人购买</navigator>-->
                    </view>
                </form>
            </view>
        </block>
    </view>
</template>

<script>
var a = require('../../@babel/runtime/helpers/defineProperty');
var t = require('../../res/www.a9a.cn.js');
var app = getApp();
var o = 2;
var n = true;
var i = uni.getStorageSync('COOK_U');
export default {
    data() {
        return {
            topbar: ['余额', '明细', '充值'],
            currentTab: 0,
            color: '',
            rgbcolor: '',
            loveb_str: '',
            loveb: '',
            CZ: {
                list: [],
                defkey: '',
                dw: '',
                zk: 0
            },
            ios_ifpay: '',
            loading_ico_flag: false,
            loading_flag: false,
            loading_str: '',
            LIST: [],
            idx_list: [],
            dl: [],
            idx_dl: 0,
            nodatabox: '',
            rmb: '',
            rmb_yj: ''
        };
    },
    onLoad: function (a) {
        var that = this;
        app.globalData.chklogin().then(function (a) {
            a || uni.navigateBack();
        });
        var n = 2 == a.currentTab ? 2 : 0;
        app.globalData.get_openid().then(function (a) {
            that.setData({
                color: app.globalData._ZEAI.color,
                rgbcolor: t.c16_rgb(app.globalData._ZEAI.color),
                loveb_str: app.globalData._ZEAI.loveb,
                currentTab: n
            });
            uni.setNavigationBarTitle({
                title: '我的' + app.globalData._ZEAI.loveb + '账户'
            });
            i = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'my_loveb.php',
                data: {
                    submitok: 'loveb',
                    openid: i.openid
                },
                success: function (a) {
                    if (1 == a.flag) {
                        if (a.CZ.list.length > 0) {
                            var t = [app.globalData._ZEAI.loveb, '明细', '充值'];
                        } else {
                            t = [app.globalData._ZEAI.loveb, '明细'];
                        }
                        if (1 != a.ios_ifpay.flag) {
                            uni.getSystemInfo({
                                success: function (a) {
                                    if ('ios' == a.platform) {
                                        t = [app.globalData._ZEAI.loveb, '明细'];
                                    }
                                }
                            });
                        }
                        that.setData({
                            loveb: a.cook_loveb,
                            CZ: a.CZ,
                            topbar: t,
                            ios_ifpay: a.ios_ifpay
                        });
                    } else {
                        uni.showToast({
                            title: a.msg,
                            icon: 'none',
                            mask: true
                        });
                    }
                }
            });
        });
    },
    onReachBottom: function () {
        if (0 != this.currentTab) {
            var that = this;
            var s = this.LIST;
            if (n) {
                n = false;
                that.setData({
                    loading_ico_flag: true
                });
                app.globalData.ajax({
                    url: 'my_loveb.php',
                    data: {
                        submitok: 'list',
                        p: o,
                        openid: i.openid
                    },
                    success: function (e) {
                        var i = e.LIST;
                        if (i.length < 1) {
                            that.setData({
                                loading_flag: true,
                                loading_ico_flag: false,
                                loading_str: '已全部加载完成'
                            });
                            return void (n = false);
                        }
                        that.setData(a({}, 'LIST[' + s.length + ']', i));
                        o += 1;
                        n = true;
                    }
                });
            }
        }
    },
    methods: {
        topbarFn: function (a) {
            var t = parseInt(a.currentTarget.dataset.idx);
            this.setData({
                currentTab: t
            });
            if (1 == t) {
                this.get_data();
            }
        },

        get_data: function () {
            app.globalData.chklogin().then(function (a) {
                a || uni.navigateBack();
            });
            n = false;
            var that = this;
            var o = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'my_loveb.php',
                data: {
                    submitok: 'list',
                    openid: o.openid
                },
                success: function (e) {
                    var o = e.LIST;
                    if (1 == e.flag) {
                        var i;
                        if (o.length >= 15) {
                            that.setData({
                                loading_flag: true,
                                loading_ico_flag: true
                            });
                        }
                        if (0 == o.length) {
                            that.setData(
                                a(
                                    {
                                        loading_flag: false
                                    },
                                    'nodatabox',
                                    true
                                )
                            );
                        } else {
                            that.setData((a((i = {}), 'LIST[0]', o), a(i, 'nodatabox', false), a(i, 'loading_flag', false), i));
                        }
                        n = true;
                    } else {
                        uni.showModal({
                            content: e.msg,
                            confirmColor: that.color,
                            confirmText: '朕知道了',
                            showCancel: false,
                            success: function (a) {
                                uni.navigateBack();
                            }
                        });
                    }
                }
            });
        },

        czliFn: function (t) {
            var e = t.currentTarget.dataset.idx;
            this.setData(a({}, 'CZ.defkey', e));
        },

        payFn: function () {
            var that = this;
            var t = that.CZ;
            var o = that.CZ.defkey;
            1 != that.ios_ifpay.flag
                ? uni.getSystemInfo({
                      success: function (n) {
                          'ios' == n.platform
                              ? uni.showModal({
                                    title: '温馨提示',
                                    content: that.ios_ifpay.tips,
                                    confirmColor: that.color,
                                    cancelText: '返回',
                                    confirmText: '联系经纪人',
                                    success: function (a) {
                                        a.confirm
                                            ? uni.redirectTo({
                                                  url: '/myPages/hongniang/hongniang'
                                              })
                                            : a.cancel && uni.navigateBack();
                                    }
                                })
                              : app.globalData.pay({
                                    data: {
                                        submitok: 'loveb_cz',
                                        rmb: t.list[o].rmb_yj
                                    }
                                });
                      }
                  })
                : app.globalData.pay({
                      data: {
                          submitok: 'loveb_cz',
                          rmb: t.list[o].rmb_yj
                      }
                  });
        }
    }
};
</script>
<style>
@import 'loveb.css';
</style>
